from PyQt5.QtCore import QDir, QFileInfo, QStandardPaths, Qt, QUrl,QSettings
import os
import json
import getpath
import sys
import logging
_setting_file="setting.json"
setting={
}
path='HKEY_CURRENT_USER\\Software\\MA_EXPLORE'
setting2 = QSettings(path, QSettings.NativeFormat)
init_value=""
def write_setting():
    logging.info("check write_setting")
    new_value=json.dumps(setting)
    if new_value==init_value:
        return
    logging.info("output")        
    setting_filename = os.path.join(getpath.getpath(), _setting_file)
    set_file=open(setting_filename, 'w',encoding="utf-8")
    set_file.write(new_value)
    set_file.close()
    if sys.platform == "linux":
        pass
    else:
        pass
        # setting2.setValue("yqbh",setting["yqbh"])
        # setting2.setValue("sblx",setting["sblx"])
        # setting2.setValue("output_folder",setting["output_folder"])
        # setting2.setValue("database",setting["database"])
        # setting2.setValue("lr",setting["lr"])
def read_setting():
    global setting,init_value
    bookmark_file_name = os.path.join(QDir.toNativeSeparators(_config_dir()),
                                  _setting_file)
    # if os.path.exists(bookmark_file_name):
    logging.info('Reading %s...' % bookmark_file_name)
    file1=open(bookmark_file_name,encoding="utf-8")
    setting=json.load(file1)
    file1.close()
    if sys.platform == "linux":
        pass
    else:
        pass
        # setting["yqbh"]=setting2.value("yqbh")
        # setting["sblx"]=setting2.value("sblx")
        # setting["output_folder"]=setting2.value("output_folder")
        # setting["database"]=setting2.value("database")
        # setting["lr"]=setting2.value("lr")
    init_value=json.dumps(setting)
def _config_dir():
    location =getpath.getpath()#QDir.currentPath()#QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
    logging.info("configdir"+location)
    return '%s' % location
def init_from_xls():
    global setting
    read_setting()
    data0="""GB/T 20123-2006
GB/T 20126-2006
GB/T 5686.5-2008
GB/T 5686.7-2008
GB/T 4701.8-2009
GB/T4701.10-2008
GB/T4699.4-2008
GB/T4699.6-2008
GB/T 4702.14-1988
GB/T 4702.16-2008
GB/T 5059.9-2008
GB/T 7731.12-2008
GB/T 8704.1-2009
GB/T 8704.3-2009
GB/T 5121.4-2008
GB/T 4698.14-2011
GB/T 223.86-2009
NACIS/C H 002:2013
NACIS/C H 006:2013
GB/T 5059.7-2014
HB 5220.3-2008
HB 5220.6-2008
YB/T 5316-2016
YB/T 5317-2016
GB/T 8647.8-2006
GB/T 8647.9-2006
YB/T 178.6-2008
GB/T 4324.27-2012
GB/T 4324.23-2012
GB/T 4333.10-2019
GB/T 24583.4-2019
GB/T 24583.6-2019
GB∕T 3286.7-2014
参照GB/T 20123-2006
GB/T 7731.10-2021
参照GB/T 4324.27-2012
参照GB/T 12690.1-2015
参照GB/T 16555-2017
GB/T 4325.21-2013
GB/T 15076.8-2008
YB/T 4908.5-2021
GB/T 4333.7-2019
GB/T 6730.61-2022"""
    ff=data0.split("\n")
    setting["ffbh_cs"]=ff
    data0="""GB/T 11261-2006
GB/T 20124-2006
GB/T 223.82-2018
GB/T5121.8-2008
GB/T 4698.7-2011
GB/T 4698.15-2011
GB/T 4325.23-2013
GB/T 4325.25-2013
HB 5220.50-2008
HB 5220.49-2008
HB 5297.24-2001
GB/T 4702.17-2016
YS/T 539.13-2009
GB/T 15076.14-2008
GB/T 4324.25-2012
GB/T 4324.26-2012
GB/T 24583.2-2019
GB/T 13747.22-2017
参照GB/T 4698.7-2011
参照GB/T 11261-2006
参照GB/T 20124-2006
参照GB/T 24583.2-2019
参照GB/T 4324.25-2012
GB/T 15076.13-2017
GB/T 15076.15-2008
YB/T 4908.6-2021
ASTM E1409-13 (Reapproved 2021)
ASTM E1447-22
参照T/CSTM 00254-2020"""
    ff=data0.split("\n")
    setting["ffbh_onh"]=ff
    write_setting()
if __name__ == '__main__':
    init_from_xls()
